package client;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JTable;
import javax.swing.JButton;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;

import server.BkMngITF;
import server.BkWatITF;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import client.Configuration;

public class BkCheckWanterGUI extends JFrame {

	private JPanel contentPane;
	private JTable table;

	/**
	 * Launch the application.
	 */
	
	private Object[][] Wanter;
	
	Configuration config=new Configuration();
	String rmiAddress=config.getRmiAddress();
	BkMngITF Mitf;
	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					BkCheckWanterGUI frame = new BkCheckWanterGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * @param  
	 */
	public BkCheckWanterGUI() {
		setTitle("\u5E94\u8058\u4EBA\u5458\u7BA1\u7406");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label = new JLabel("\u5E94\u8058\u4EBA\u5458\u4FE1\u606F\uFF1A");
		label.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		label.setBounds(39, 34, 106, 18);
		contentPane.add(label);
		
		JButton button_2 = new JButton("\u8058\u7528\u8BE5\u4EBA");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					Mitf = (BkMngITF) Naming.lookup(rmiAddress+"BankManager");
					int a[]=table.getSelectedRows();
					int ID=(Integer)table.getValueAt(a[0], 0);
					String name=(String)table.getValueAt(a[0], 1);
					Mitf.employ(ID, name);
					
				} catch (MalformedURLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (RemoteException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (NotBoundException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
			}
		});
		button_2.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		button_2.setBounds(265, 202, 130, 36);
		contentPane.add(button_2);
		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(39, 62, 356, 122);
		contentPane.add(scrollPane);
		
		Wanter=new Object[7][];//////得到行
		
			try {
				Mitf = (BkMngITF) Naming.lookup(rmiAddress+"BankManagerAccount");
				for(int i=0;i<1;i++){
			Wanter[i]=new Object[2];
			Wanter[i][0]=new Integer(i+1);
			Wanter[i][1]=new String(String.format("%tF",Mitf.getName(i+1)));

			}
			} catch (MalformedURLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (RemoteException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (NotBoundException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			
			
		table = new JTable();
		table.setModel(new DefaultTableModel(
				
				Wanter,
				
			new String[] {
				"\u8EAB\u4EFD\u8BC1\u53F7", "\u59D3\u540D"
			}
		));
		scrollPane.setViewportView(table);
		
		JButton button = new JButton("\u8FD4\u56DE");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				BkManagerWorkGUI frame = new BkManagerWorkGUI();
				frame.setLocationRelativeTo(null);
				frame.setVisible(true);
				dispose();
			}
		});
		button.setFont(new Font("微软雅黑", Font.PLAIN, 13));
		button.setBounds(341, 10, 83, 22);
		contentPane.add(button);
	}


}
